<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义对象</title>
</head>
<body>

</body>
<script>
    //定义一个类
   function Person(){}

    //创建一个对象
    var p1 = new Person()
    p1.name = "聂茹风"
    p1.age = 17
    p1.sleep = function(){
       alert("我叫" + p1.name + "我会睡觉")
    }

    console.log(p1)
    p1.sleep()

    //创建对象方式二
    var p2 = {
       "name":"谈心与",
        "age": 30,
        "address":"河北张家口",
        "eat":function(){
           console.log("我叫" + this.name+",今年"+this.age+"岁了,我爱吃")
        }

    }

    console.log(p2)
    p2.eat()
</script>
</html>